<script language="javascript">
	function viewThanhVienByCapDo(CapDo){
		window.location='?mod=member&level=' + CapDo;
	}
	function viewThanhVienByLocation(LID){
		window.location='?mod=member&location=' + LID;
	}
	function viewThanhVienByStatus(SID){
		window.location='?mod=member&banned=' + SID;
	}
	function viewThanhVienByHOT(HID){
		window.location='?mod=member&vip=' + HID;
	}
	function viewThanhVienByOrder(Order){
		window.location='?mod=member&order=' + Order;
	}
	function viewThanhVienByTrangThai(TrangThai){
		window.location='?mod=member&status=' + TrangThai;
	}
</script>
<?
if(isset($_GET['method']))
{
	$method = $_GET['method'];
	if($method=="del"){
		$sListId="";
		if(isset($_POST["chon"]))$sListId=$_POST["chon"];
		$sql="delete from ".$prefix."nguoidung where u_id in('".str_replace(",","','",$sListId)."')";
		mysql_query($sql);
		Redirect("Bạn đã xoá thành công","?mod=member");
	}else if($method=="banned"){
		$IdList=$_GET["id"];
		$banned=$_GET["banned"];
		if($banned==1) $iact=0;else $iact=1;
		$sql="update ".$prefix."nguoidung set u_banned=$iact where u_id=$IdList";
		mysql_query($sql);
		Redirect("","?mod=member");		
	}else if($method=="delete"){
		$IdList=$_GET["id"];
		$sql="delete from ".$prefix."nguoidung where u_id=$IdList";
		mysql_query($sql);
		Redirect("Đã xóa thành công","?mod=member");		
	}
    else if ($method=="reset") {
        $id = $_GET['id'];
        $sql = "UPDATE ".$prefix."nguoidung SET `u_pass`="  ."'". md5('onepixel') ."'"." WHERE u_id=$id";
        mysql_query($sql);
        Redirect("Đã reset mật khẩu thành công","?mod=member");
    }
    
}
$where = "";
$order ="";
if(isset($_GET['level']))
{
	$level = $_GET['level'];
	if($level=="all"){
		$where = $where;
	}else{
		$where .=" where u_capdo=$level";
	}
	$order .= " order by u_ngaydangki DESC";
}
else if(isset($_GET['location'])){
	$location = $_GET['location'];
	$where .=" where u_tinhthanh=$location";
	$order .= " order by u_ngaydangki DESC";
}else if(isset($_GET['banned'])){
	$act = $_GET['banned'];
	$where .= " where u_banned=$act";
	$order .= " order by u_ngaydangki DESC";
}else if(isset($_GET['order'])){
	$iorder = $_GET['order'];
	$where = $where;
	if($iorder=="DESC"){
		$order .= " order by u_ngaydangki DESC";
	}else{
		$order .= " order by u_ngaydangki ASC";
	}
}else{
	$where = $where;
	$order .= " order by u_ngaydangki DESC";
}
	///////Paging
	$strSQL = "select * from ".$prefix."nguoidung".$where.$order."";
	//echo $strSQL;
	$pp=10; 
	$parr=array();
	$parr=paging($strSQL,$pp);
	$page=$parr[0];
	$limitvalue=$parr[1];
	$numofpages=$parr[2];
	$strSQL.=" LIMIT $limitvalue, $pp";
	$rs = mysql_query($strSQL) or die('Not query');
	$i=0;
	$isexits=false;
	
	if(mysql_num_rows($rs)) $isexits=true;
?>
<div class="newsList-path"></div>
	<div style="margin-bottom:5px; font-size:14px;">
	<?
	$sql = "select count(*) as total from ".$prefix."nguoidung".$where."";
	$result = mysql_query($sql) or die("Can't connect database");
	$row = mysql_fetch_array($result);
	?>
	 Có <?=$row['total']?> thành viên được tìm thấy </div>
	<div align="right" class="newsList-search-up">
	  <select name="FilterByCapDo" id="CapDo" onchange="return(viewThanhVienByCapDo(this.value));">
	<option value="">--Cấp độ--</option>
	<option value="all">Tất cả</option>
	<option value="5">5 Sao</option>
	<option value="4">4 Sao</option>
	<option value="3">3 Sao</option>
	<option value="2">2 Sao</option>
	<option value="1">1 Sao</option>
	<option value="0">0 Sao</option>
	  </select>
	  &nbsp;<select name="FilterByTinhThanh" id="LID" onchange="return(viewThanhVienByLocation(this.value));">
	<option value="">--Khu vực--</option>
	<?
	$sql = "select * from ".$prefix."tinhthanh order by tt_ten ASC";
	$result = mysql_query($sql) or die("Can't connect database");
	while($row = mysql_fetch_array($result))
	{
	?>	
	<option value="<?=$row['tt_id']?>"><?=$row['tt_ten']?></option>
	<? }?>	
	  </select>
	  &nbsp;<select name="FilterByStatus" id="SID" onchange="return(viewThanhVienByStatus(this.value));">
	<option value="">--Tình trạng--</option>
	<option value="1">Banned</option>
	<option value="0">Khác</option>
	  </select>
	  &nbsp;<select name="FilterByOrder" id="Order" onchange="return(viewThanhVienByOrder(this.value));">
	<option value="">--Sắp xếp--</option>
	<option value="ASC">Mới nhất</option>
	<option value="DESC">Cũ nhất</option>
	  </select>

</div>
	<form name="frmListSp" method="post" action="?mod=member&method=del" onSubmit="return checkInput(this,'Bạn hãy chọn ít nhất một giá trị','Bạn chắc chắn muốn xoá không');">
	<input type="hidden" name="chon" />
	<table width="100%" border="1" bordercolor="#B2DAEE" cellpadding="4">
		<tr class="newsList-content-head">
		<td width="4%" class="newsList-content-view"><input type="checkbox" name="chkall" value="0" <? if($isexits) echo "onClick=\"docheck(this.form,0);\""?>></td>
			<td width="41%" class="newsList-content-title">Thông tin thành viên </td>

		  <td width="15%" class="newsList-content-view"><div align="center">Cấp độ </div></td>
		  <td width="8%" class="newsList-content-view"><div align="center">Banned </div></td>
		  <td width="14%" class="newsList-content-view"><div align="center">Ngày đăng ký </div></td>
			<td width="8%" class="newsList-content-position">Khu vực</td>
			<td width="10%" class="newsList-content-position">Tùy chọn </td>
		</tr>
				<?
				while($rows = mysql_fetch_array($rs))
				{
					$i++;
					$u_id = $rows['u_id'];
					$u_ngaysinh = $rows['u_ngaysinh'];
					$u_name = $rows['u_name'];
					$u_capdo = $rows['u_capdo'];
					$u_tinhthanh = $rows['u_tinhthanh'];
					$u_ngaydangki = $rows['u_ngaydangki'];
					$u_tenshop = $rows['u_tenshop'];
					$u_banned = $rows['u_banned'];
					$u_email = $rows['u_email'];
					$u_gioitinh = $rows['u_gioitinh'];
				?>				
		<tr onmouseover="this.bgColor='#FEF2CB';" onmouseout="this.bgColor='#FFFFFF';" class="newsList-content-list" <? if($i%2==0) echo "bgcolor='#f2fff2'";?>>
			<td class="newsList-content-title"><input type="checkbox" name="Xoa" value="<?=$u_id?>" onClick="docheckone(this.form);"></td>
			<td class="newsList-content-title">
            	<table cellpadding="0" cellspacing="0" width="100%">
                <tr>
					<td colspan="2">
						<a class="newsList-link newsList-name" href="">
						<b><?=$u_name?></b></a>&nbsp;<i>(<?=$u_tenshop?>)</i>					</td>
                <tr>
                    <td><div class="newsList-user-id" >Ngày sinh: <?=format_date($u_ngaysinh);?>&nbsp;|&nbsp;<? if($u_gioitinh==1){ echo "Nam";}else{ echo "Nữ";}?></div></td>
                	<td align="right"><div class="newsList-time"><span class="newsList-date"><?=$u_email?></span></div></td>
                </tr>
                </table>				</td>
			<td class="newsList-content-view"><div align="center"><?=$u_capdo;?></div></td>
			<td class="newsList-content-view"><div align="center"><a href="?mod=member&method=banned&banned=<?=$u_banned;?>&id=<?=$u_id?>"><?=ImgActive($u_banned);?></a></div></td>
			<td class="newsList-content-view"><div align="center"><?=format_date($u_ngaydangki);?></div></td>
			<td class="newsList-content-position"><a class="newsList-link" href="?mod=member&amp;location=<?=$u_tinhthanh?>&amp;portal=<?=$mod?>">
			  <?=layTinhThanh($u_tinhthanh);?>
			  </a></td>
			<td class="newsList-content-position"><div align="center"><a href="?mod=member&amp;method=reset&amp;id=<?=$u_id?>" class="menu"><img src="images/edit.gif" border="0" /></a>&nbsp; <a href="?mod=member&amp;method=delete&amp;id=<?=$u_id?>" class="menu" onclick="return confirm('Bạn có chắc chắn muốn xóa không?')"><img src="images/delete_on.gif" border="0" /></a></div></td>
		</tr>
		<? }?>
	<tr>
   <td colspan="9" align="center">
   <input type="submit" name="submit" value="   Xoá   " class="Button">
   <input type="reset" value="Làm lại" class="Button">   </td>
   </tr>
</table>
	</form>
	<div class="newsList-pagging">
	<div class="raovat-paging-bound">
	<span style="padding:5px;">
	<p align="center" class="font">
			<?php echo page_div( "?mod=member&p=%d_pg", "10", ceil ( $numofpages ), $page ); ?>
	</p>
	</span>
	</div>
	</div>
	<div class="newsList-button-back"><a href="javascript: history.back()">[Quay lại]</a></div>